package com.demo.config;

import com.demo.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 权限拦截器配置
 */
@Configuration
public class AuthConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login", "/user/register", "/user/reset", "/**/export", "/**/import", "/file/**")
                // 放行OpenAPI 3和Knife4j文档
                .excludePathPatterns("/doc.html", "/v3/api-docs/**", "/swagger-ui.html", "/swagger-ui/**", "/webjars/**")
                // 放行websocket
                .excludePathPatterns("/ws/**");
    }
}
